#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define OJ_TEST 0
#define LOCAL_TEST 0

#define M 901

static int max(int a, int b){ return a>b?a:b; }
static int min(int a, int b) { return a<b?a:b; }
static int num[M];
static void solve(void){
	int cs, n;
	int i, j, ans;
	for(scanf("%d", &cs); cs>0; --cs){
		scanf("%d", &n);
		for(i=0; i<n; ++i){
			scanf("%d", num+i);
		}
		ans=0;
		for(j=1; j<n; ++j){
			for(i=0; i<j; ++i){
				if(num[i]>num[j]){
					++ans;
				}
			}
		}
		printf("Optimal train swapping takes %d swaps.\n", ans);
	}
}
#if OJ_TEST
	int main(int ac, char *av[]){
		solve();
		return 0;
	}
#elif  LOCAL_TEST
	void run(void){
		solve();
	}

#else

#endif
